package com.draven.admin.controller;

import com.draven.common.entity.Note;
import com.draven.common.entity.NoteCategory;
import com.draven.common.entity.NoteTag;
import com.draven.system.service.INoteCategoryService;
import com.draven.system.service.INoteService;
import com.draven.system.service.INoteTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 首页控制器
 * 
 * @author draven
 */
@Controller
public class IndexController {

    @Autowired
    private INoteService noteService;

    @Autowired
    private INoteCategoryService noteCategoryService;

    @Autowired
    private INoteTagService noteTagService;

    /**
     * 首页
     */
    @GetMapping({"/", "/index"})
    public String index(ModelMap mmap) {
        // 获取最近笔记
        List<Note> recentNotes = noteService.selectRecentNotes(5);
        // 获取热门笔记
        List<Note> hotNotes = noteService.selectHotNotes(5);
        // 获取分类列表（包含笔记数量）
        List<NoteCategory> categories = noteCategoryService.selectCategoryListWithCount();
        // 获取热门标签
        List<NoteTag> hotTags = noteTagService.selectHotTags(10);

        mmap.put("recentNotes", recentNotes);
        mmap.put("hotNotes", hotNotes);
        mmap.put("categories", categories);
        mmap.put("hotTags", hotTags);

        return "index";
    }

    /**
     * 笔记管理页面
     */
    @GetMapping("/admin")
    public String admin() {
        return "admin/index";
    }
}